package com.briup.day16;

/**
 * @author ThinkBook
 */
public class Test01_Impl {
    public static void main(String[] args) {
        Animal2 a = new Monkey("yellow",2,"小悟空");
        a.eat();
        a.sleep();
        System.out.println("----------");

        //接口多态测试
        if (a instanceof Monkey){
            IJumpAble j = (IJumpAble) a;
            j.jump();
        }
        if (a instanceof Monkey){
            ICycleAble c = (ICycleAble) a;
            c.cycle();
        }
    }
}
abstract class Animal2{
    private String color;
    private int age;

    public Animal2() {}
    public Animal2(String color, int age) {
        this.color = color;
        this.age = age;
    }

    // 抽象方法
    public abstract void eat();
    public abstract void sleep();
}
class Monkey extends Animal2 implements ICycleAble,IJumpAble{
    private String name;

    //自定义构造方法
    public Monkey() {}

    public Monkey(String color, int age, String name) {
        super(color, age);
        this.name = name;
    }

    //重写从父类继承的方法
    @Override
    public void eat() {
        System.out.println("猴子" + name + " 喜欢吃大桃子");
    }
    @Override
    public void sleep() {
        System.out.println("猴子" + name + " 喜欢在树上睡觉");
    }

    @Override
    public void cycle() {
        System.out.println("猴子 " + name + " 能够骑自行车");
    }

    @Override
    public void jump() {
        System.out.println(name + " 能够跳火圈");
    }
}
interface ICycleAble{
    public abstract void cycle();
}
interface IJumpAble{
    //默认修饰符为：public abstract
    void jump();
}
